package com.itrus.serviceframe;

import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class DataPacket
{
  private NVRepository m_anvp;
  private int m_status = 0;

  public DataPacket(int paramInt)
  {
    this.m_anvp = new NVRepository(paramInt);
  }

  static int byte2int(byte paramByte)
  {
    if (paramByte >= 0)
      return paramByte;
    return paramByte + 256;
  }

  static int bytes2int(byte[] paramArrayOfByte)
  {
    return (((0xFF & paramArrayOfByte[0]) << 8 | 0xFF & paramArrayOfByte[1]) << 8 | 0xFF & paramArrayOfByte[2]) << 8 | 0xFF & paramArrayOfByte[3];
  }

  public static DataPacket getInstance(InputStream paramInputStream, boolean paramBoolean)
    throws IOException, EOFException
  {
    DataPacket localDataPacket = new DataPacket(0);
    byte[] arrayOfByte1 = new byte[8192];
    NameValuePair.read(paramInputStream, arrayOfByte1, 0, 4);
    int j;
    if ((0x80 & arrayOfByte1[0]) == 0)
      if (paramBoolean)
      {
        localDataPacket.setVersion(2);
        j = bytes2int(arrayOfByte1);
      }
    while (true)
      if (j > 2147483647)
      {
        throw new IOException("接受数据包长度超过2G限制，Length=[" + j + "]。");
        localDataPacket.setVersion(1);
        break;
        byte[] arrayOfByte2 = new byte[1];
        NameValuePair.read(paramInputStream, arrayOfByte2, 0, 1);
        int i = byte2int(arrayOfByte2[0]);
        if (i == 3)
        {
          localDataPacket.setVersion(3);
          arrayOfByte1[0] = ((byte)(0x7F & arrayOfByte1[0]));
          j = bytes2int(arrayOfByte1);
        }
        else
        {
          throw new IOException("不支持的协议版本，Version=[" + i + "]。");
        }
      }
    if (arrayOfByte1.length > j)
    {
      ((byte[])null);
      arrayOfByte1 = new byte[j];
    }
    NameValuePair.read(paramInputStream, arrayOfByte1, 0, 2);
    localDataPacket.m_status = NameValuePair.bytes2short(arrayOfByte1);
    NameValuePair.read(paramInputStream, arrayOfByte1, 0, 2);
    int k = NameValuePair.bytes2short(arrayOfByte1);
    for (int m = 0; ; m++)
    {
      if (m >= k)
        return localDataPacket;
      NameValuePair localNameValuePair = NameValuePair.getInstance(paramInputStream, localDataPacket.getVersion());
      localDataPacket.getNVRepository().add(localNameValuePair);
    }
  }

  public static String getValue(String paramString, DataPacket paramDataPacket)
  {
    NVRepository localNVRepository = paramDataPacket.getNVRepository().find(paramString);
    if (localNVRepository.size() == 0);
    String str;
    do
    {
      return null;
      str = new String(localNVRepository.elementAt(0).getValue());
    }
    while (str.length() <= 0);
    return str;
  }

  static void int2bytes(int paramInt, byte[] paramArrayOfByte)
  {
    paramArrayOfByte[3] = ((byte)(paramInt & 0xFF));
    paramArrayOfByte[2] = ((byte)((0xFF00 & paramInt) >> 8));
    paramArrayOfByte[1] = ((byte)((0xFF0000 & paramInt) >> 16));
    paramArrayOfByte[0] = ((byte)((0xFF000000 & paramInt) >> 24));
  }

  public int getLength()
    throws IOException
  {
    int i = 4 + this.m_anvp.getSize();
    if (i > 2147483647)
      throw new IllegalStateException();
    int j = getVersion();
    if ((j != 1) && (j != 2))
    {
      if (getVersion() == 3)
        i++;
    }
    else
      return i + 4;
    throw new IOException("不支持的协议版本，Version=[" + j + "]。");
  }

  public NVRepository getNVRepository()
  {
    return this.m_anvp;
  }

  public int getStatus()
  {
    return this.m_status;
  }

  public int getVersion()
  {
    return this.m_anvp.getVersion();
  }

  public int serialize(OutputStream paramOutputStream)
    throws IOException
  {
    int i = 4 + this.m_anvp.getSize();
    if (i > 2147483647)
      throw new IllegalStateException();
    byte[] arrayOfByte = new byte[4];
    new byte[i];
    int j = getVersion();
    int k;
    int m;
    if ((j == 1) || (j == 2))
    {
      int2bytes(i, arrayOfByte);
      paramOutputStream.write(arrayOfByte);
      if (getVersion() == 3)
        paramOutputStream.write(3);
      NameValuePair.short2bytes(this.m_status, arrayOfByte);
      paramOutputStream.write(arrayOfByte, 0, 2);
      NameValuePair.short2bytes(this.m_anvp.size(), arrayOfByte);
      paramOutputStream.write(arrayOfByte, 0, 2);
      k = 0;
      m = this.m_anvp.size();
    }
    while (true)
    {
      if (k >= m)
      {
        return i;
        if (getVersion() == 3)
        {
          i++;
          int2bytes(i, arrayOfByte);
          arrayOfByte[0] = ((byte)(0x80 | arrayOfByte[0]));
          break;
        }
        throw new IOException("不支持的协议版本，Version=[" + j + "]。");
      }
      NameValuePair localNameValuePair = this.m_anvp.elementAt(k);
      localNameValuePair.setVersion(getVersion());
      localNameValuePair.serialize(paramOutputStream);
      k++;
    }
  }

  public void setNVRepository(NVRepository paramNVRepository)
  {
    this.m_anvp = paramNVRepository;
  }

  public void setStatus(int paramInt)
  {
    this.m_status = paramInt;
  }

  public void setVersion(int paramInt)
  {
    this.m_anvp.setVersion(paramInt);
  }

  public String toString()
  {
    StringBuffer localStringBuffer = new StringBuffer();
    localStringBuffer.append("Status: " + Integer.toHexString(this.m_status).toUpperCase() + "\n");
    int i = this.m_anvp.size();
    if (i > 0);
    for (int j = 0; ; j++)
    {
      if (j >= i)
        return localStringBuffer.toString();
      localStringBuffer.append(this.m_anvp.elementAt(j).toString() + "\n");
    }
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.itrus.serviceframe.DataPacket
 * JD-Core Version:    0.6.2
 */